package com.lin.cms.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.lin.cms.domain.Model;

public class ModelValidator implements Validator {

	@SuppressWarnings("unchecked")
	public boolean supports(Class clazz) {
		return Model.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "modelId", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "modelName", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "modelPath", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "titleImgWidth", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "titleImgHeight", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contentImgWidth", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "contentImgHeight", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "priority", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "hasContent", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isDisabled", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "isDef", "required");
	}

}
